//
//  OrderTableViewCell.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/5/18.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "OrderTableViewCell.h"

@implementation OrderTableViewCell

/**
 生成Cell
 
 @param tableView 列表
 @return ***
 */
+(instancetype)cellWithTableView:(UITableView*)tableView{
    static NSString *CellIdentifer = @"OrderTableViewCell";
    OrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifer];
    if(!cell){
        [tableView registerNib:[UINib nibWithNibName:CellIdentifer bundle:nil] forCellReuseIdentifier:CellIdentifer];
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifer];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

/**
 设置数据

 @param dataInfo 数据字典
 */
-(void)setDataInfo:(HQOrder *)dataInfo{
    _dataInfo = dataInfo;
    self.shareButton.dataInfo = _dataInfo;
    
    NSTimeInterval interval    = [_dataInfo.o_ctime doubleValue];
    NSDate *date               = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString       = [formatter stringFromDate: date];
    
    [self sourceLabel:self.itemTime withTitle:@"日期: " withData:dateString];
    [self sourceLabel:self.itemPhone withTitle:@"电话: " withData:_dataInfo.o_userphone];
    [self sourceLabel:self.itemName withTitle:@"名称: " withData:_dataInfo.o_usernam];
    [self sourceLabel2:self.itemPrice withTitle:@"金额: " withData:_dataInfo.price];
}

-(void)sourceLabel:(UILabel *)sourceLabel withTitle:(NSString *)title withData:(NSString *)data{
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",title,data]];
    [attributeStr addAttribute:NSForegroundColorAttributeName value:[self colorHexValue:0x333333] range:NSMakeRange(0,[title length])];
    [attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0,[title length])];
    [attributeStr addAttribute:NSForegroundColorAttributeName value:[self colorHexValue:0x666666] range:NSMakeRange([title length],[data length])];
    [attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange([title length],[data length])];
    sourceLabel.attributedText = attributeStr;
}

-(void)sourceLabel2:(UILabel *)sourceLabel withTitle:(NSString *)title withData:(NSString *)data{
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@￥%@",title,data]];
    [attributeStr addAttribute:NSForegroundColorAttributeName value:[self colorHexValue:0x333333] range:NSMakeRange(0,[title length])];
    [attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0,[title length])];
    [attributeStr addAttribute:NSForegroundColorAttributeName value:[self colorHexValue:0xFD5900] range:NSMakeRange([title length],[data length]+1)];
    [attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:NSMakeRange([title length],1)];
    [attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange([title length]+1,[data length])];
    [attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:NSMakeRange([title length]+[data length]-1,2)];
    sourceLabel.attributedText = attributeStr;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
